package com.jc.service.xordermarge;

import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import com.jc.cds.model.CustomerXorderMarge;
import com.jc.ds.base.service.BaseServiceException;
import com.jc.ds.base.service.BaseServiceImpl;
import com.jc.ds.mapper.BaseCustomMapper;
import com.jc.ds.model.XorderMarge;
import com.jc.framework.enums.Booleans;
import com.jc.framework.enums.OrderMargeType;

@Service
public class XorderMargeServiceImpl extends BaseServiceImpl<XorderMarge, CustomerXorderMarge, Long> implements XorderMargeService {

	@Override
	public BaseCustomMapper<CustomerXorderMarge, Long> getCustomMapper() {
		return null;
	}
	
	public XorderMarge getXorderMarge(Long orderId) {
		XorderMarge marge = new XorderMarge();
		marge.setType(OrderMargeType.ORDER_ID_FLUSH.getName());
		marge.setOrderId(orderId);
		marge.setIsDelete(Booleans.FALSE.getName());
		List<XorderMarge> _orderMargeList = queryAll(marge);
		if(CollectionUtils.isEmpty(_orderMargeList)) {
			return null;
		}
		if(_orderMargeList.size() > 1) {
			throw new BaseServiceException("错误, " + orderId + " 该条订单号发现多条对应的临时订单号");
		}
		return _orderMargeList.get(0);
	}
	
	public XorderMarge getXorderMargeByChannelOrderId(String newChannelOrderId) {
		XorderMarge marge = new XorderMarge();
		marge.setType(OrderMargeType.ORDER_ID_FLUSH.getName());
		marge.setNewChannelOrderId(newChannelOrderId);
		marge.setIsDelete(Booleans.FALSE.getName());
		List<XorderMarge> _orderMargeList = queryAll(marge);
		if(CollectionUtils.isEmpty(_orderMargeList)) {
			return null;
		}
		if(_orderMargeList.size() > 1) {
			throw new BaseServiceException("错误, " + newChannelOrderId + " 该条订单号发现多条对应的有效临时订单号");
		}
		return _orderMargeList.get(0);
	}
	
	
	
	
	
	public List<XorderMarge> getChildOrderList(String newChannelOrderId){
		XorderMarge marge = new XorderMarge();
		marge.setType(OrderMargeType.ORDER_MARGE.getName());
		marge.setNewChannelOrderId(newChannelOrderId);
		marge.setIsDelete(Booleans.FALSE.getName());
		List<XorderMarge> _orderMargeList = queryAll(marge);
		if(CollectionUtils.isEmpty(_orderMargeList)) {
			return null;
		}
		return _orderMargeList;
		
		
	}
	
	
}
